package com.laker.autotest.desktop.utils;

import com.github.kwhat.jnativehook.NativeInputEvent;
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
import com.github.kwhat.jnativehook.mouse.NativeMouseEvent;
import com.github.kwhat.jnativehook.mouse.NativeMouseWheelEvent;

public class ObjectUtil {

    public static final int NATIVE_KEY_EVENT = 0;
    public static final int NATIVE_MOUSEWHEEL_EVENT = 1;
    public static final int NATIVE_MOUSE_EVENT = 2;

    public static String ObjectToString(NativeKeyEvent object) {
        return NATIVE_KEY_EVENT +
                "#" + object.getID() +
                "#" + object.getModifiers() +
                "#" + object.getRawCode() +
                "#" + object.getKeyCode() +
                "#" + object.getKeyChar() +
                "#" + object.getKeyLocation();
    }

    public static String ObjectToString(NativeMouseEvent object) {
        return NATIVE_MOUSE_EVENT +
                "#" + object.getID() +
                "#" + object.getModifiers() +
                "#" + object.getX() +
                "#" + object.getY() +
                "#" + object.getButton();
    }

    public static String ObjectToString(NativeMouseWheelEvent object) {
        return NATIVE_MOUSEWHEEL_EVENT +
                "#" + object.getID() +
                "#" + object.getModifiers() +
                "#" + object.getX() +
                "#" + object.getY() +
                "#" + object.getScrollType() +
                "#" + object.getScrollAmount() +
                "#" + object.getWheelRotation();
    }

    public static NativeInputEvent StringToObject(String[] v) {
        NativeInputEvent o = null;
        int i;
        switch (Integer.parseInt(v[1])) {
            case NATIVE_KEY_EVENT:
                i = 2;
                o = new NativeKeyEvent(Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), v[i++].toCharArray()[0], Integer.parseInt(v[i++]));
                break;
            case NATIVE_MOUSE_EVENT:
                i = 2;
                o = new NativeMouseEvent(Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), 1, Integer.parseInt(v[i++]));
                break;
            case NATIVE_MOUSEWHEEL_EVENT:
                i = 2;
                o = new NativeMouseWheelEvent(Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), 1, Integer.parseInt(v[i++]), Integer.parseInt(v[i++]), Integer.parseInt(v[i++]));
                break;
        }
        return o;
    }
}
